﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Data;


namespace Xiaov.SmartWeb.Application.HXZB
{
    public partial class JszbRightData : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                #region 获取参数
                string zbbm = "", dwbm = "", nf = "", yf = "", type = "";
                if (Request.QueryString["zbbm"] != null)
                {
                    zbbm = Request.QueryString["zbbm"].ToString();
                }
                if (Request.QueryString["dwbm"] != null)
                {
                    dwbm = Request.QueryString["dwbm"].ToString();
                }
                if (Request.QueryString["nf"] != null && Request.QueryString["yf"] != null)
                {
                    nf = Request.QueryString["nf"].ToString();
                    yf = Request.QueryString["yf"].ToString();
                }
                if (Request.QueryString["type"] != null)//数据信息 标题，本年数据，去年数据
                {
                    type = Request.QueryString["type"].ToString();
                }
                #endregion
                StringBuilder sbSql = new StringBuilder();
                sbSql.Append("select b.yf,a.bnlj bnlj,b.bnlj qntqlj from ");
                sbSql.Append("(select * from tg07 t WHERE zbbm='" + zbbm + "' and nf={1} and yf<={0} and dwbm='{2}') a,");
                sbSql.Append("(select * from tg07 t WHERE zbbm='" + zbbm + "' and nf={1}-1 and yf<={0} and dwbm='{2}') b ");
                sbSql.Append("where a.yf(+)=b.yf ");
                sbSql.Append("order by to_number(b.yf)");
                DataSet ds = Maticsoft.DBUtility.DbHelperOra.Query(string.Format(sbSql.ToString(), "12", nf, dwbm));
                #region 输出数据
                if (ds != null && ds.Tables[0].Rows.Count > 0)
                {
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        if (ds.Tables[0].Rows[i]["bnlj"].ToString() == "")
                        {
                            ds.Tables[0].Rows[i]["bnlj"] = 0;
                        }
                        if (ds.Tables[0].Rows[i]["qntqlj"].ToString() == "")
                        {
                            ds.Tables[0].Rows[i]["qntqlj"] = 0;
                        }
                        if (type == "title")
                        {
                            if (i != ds.Tables[0].Rows.Count - 1)
                            {
                                Response.Write(ds.Tables[0].Rows[i]["yf"].ToString() + "月\t");
                            }
                            else
                            {
                                Response.Write(ds.Tables[0].Rows[i]["yf"].ToString() + "月");
                            }
                        }
                        else if (type == "bnlj")
                        {
                            if (i != ds.Tables[0].Rows.Count - 1)
                            {
                                Response.Write(ds.Tables[0].Rows[i]["bnlj"].ToString() + "\t");
                            }
                            else
                            {
                                Response.Write(ds.Tables[0].Rows[i]["bnlj"].ToString());
                            }
                        }
                        else if (type == "qntq")
                        {
                            if (i != ds.Tables[0].Rows.Count - 1)
                            {
                                Response.Write(ds.Tables[0].Rows[i]["qntqlj"].ToString() + "\t");
                            }
                            else
                            {
                                Response.Write(ds.Tables[0].Rows[i]["qntqlj"].ToString());
                            }
                        }
                    }
                    Response.End();
                }
                #endregion               
            }
        }
    }
}